﻿using System.IO;
using System.Reflection;

namespace github.heerheer.card2.Code.Helper
{
    public class I18nHelper
    {
        private string languagePath;

        public string readText(string key)
        {
            foreach (var item in File.ReadAllLines(languagePath))
            {
                if (item.Length < 2)
                {
                    return key;
                }
                if (item.Split('=')?[0] == key)
                {
                    return item.Split('=')[1];
                }
            }
            return key;
        }

        public void setPath(string path)
        {
            
            if (!File.Exists(path))
            {
                File.Create(path).Close();
                File.WriteAllText(path,
                    new StreamReader(
                        Assembly.GetExecutingAssembly().GetManifestResourceStream(
                            //github.heerheer.card2.Code.Langs.zh_cn.lang
                            "github.heerheer.card2.Code.Helper.Langs.zh_cn.lang")
                        ).ReadToEnd()
                );
            }
            languagePath = path;
        }
    }
}